<?php
namespace User\Controller;
use Think\Controller;

class ImController extends Controller{
    
//    curl -X POST "https://a1.easemob.com/easemob-demo/chatdemo/token" -d '{"grant_type":"client_credentials","client_id":"YXA6wDs-MARqEeSO0VcBzaqg11","client_secret":"YXA6JOMWlLap_YbI_ucz77j-4-mI0dd"}
    private $org_name       = "";
    private $app_name       = "";
    private $client_id      = "";
    private $client_secret  = "";

    public function _initialize(){
        $config = C('IM');
        $this->org_name     = $config['org_name'];
        $this->app_name     = $config['app_name'];
        $this->client_id    = $config['client_id'];
        $this->client_secret= $config['client_secret'];
    }

    public function getToken(){
        //先从数据库获取token
        $token = M("Config")->field("value, updatetime")->where(array("key" => "TOKEN"))->find();
        //判断token时间是否过期
        if( (time()-$token['updatatime'])/3600/24 >= 7 ){
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, "https://a1.easemob.com/easemob-demo/chatdemo/token");
            curl_setopt($ch, CURLOPT_POST);

            // 抓取URL并把它传递给浏览器
            curl_exec($ch);

            // 关闭cURL资源，并且释放系统资源
            curl_close($ch);
        }
    }
//    curl -X POST "https://a1.easemob.com/easemob-demo/chatdemo/token" -d '{"grant_type":"client_credentials","client_id":"YXA6wDs-MARqEeSO0VcBzaqg11","client_secret":"YXA6JOMWlLap_YbI_ucz77j-4-mI0dd"}'
    public function register(){
        
    }
}